package com.laicunba.ext.web.controller.web;

import javax.servlet.http.HttpServletRequest;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.laicunba.util.StringUtil;
import com.laicunba.ext.service.SlaveFinancingTargetService;
import com.laicunba.ext.web.controller.BaseController;

@Controller
@RequestMapping(value = "/webapi/ext")
public class FinancingTargetFindbyIdAPIController extends BaseController {
	@Autowired
	private SlaveFinancingTargetService slaveFinancingTargetService;

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/financing_target_findby_id.htm", method=RequestMethod.GET)
	public String financingTargetFindbyId(HttpServletRequest request) {
		JSONObject json = new JSONObject();
		
		String id = request.getParameter("id");
		String callback = request.getParameter("callback");
		if(StringUtil.isNotEmpty(callback) && StringUtil.isNotEmpty(id)) {
			json.put("code", ResponseCode.SUCCESS);
			json.put("data", slaveFinancingTargetService.getFinancingTarget(id));
		} else {
			json.put("code", ResponseCode.PARAM_ERROR);
			json.put("data", null);
		}
		
		return callback + "(" + toJsonObject(json) + ")";
	}
}
